<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    
    <!-- Bootstrap CSS -->
    <link href="/static/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap-Table CSS -->
    <link href="/static/vendor/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    
    <style>
        /* 主要内容区域 */
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            background-color: #f8f9fa;
            padding: 20px;
            margin: 0;
            height: 100%;
        }
                /* 滑动开关样式 */
        .switch-container {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .switch {
            position: relative;
            display: inline-block;
            width: 60px;
            height: 30px;
        }
        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #2c2c2c;
            transition: .4s;
            border-radius: 34px;
        }
        .slider:before {
            position: absolute;
            content: "";
            height: 22px;
            width: 22px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }
        input:checked + .slider:before {
            transform: translateX(30px);
        }
        .switch-label {
            font-weight: 500;
            color: #555;
        }
        .switch-label.active {
            font-weight: bold;
            color: #2c3e50;
        }
        



        /* 工具栏样式 - 确保所有内容在一行 */
        #toolbar {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: nowrap;
            margin-bottom: 15px;
            padding: 10px;
            background: #fff;
            border-radius: 5px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        #start-value {
            width: 80px;
            border-radius: 20px;
            border: 1px solid #ddd;
            padding: 0.3rem 1rem;
            text-align: center;
        }
        #filter-group {
            background: #f8f9fa;
            padding: 0.5rem;
            border-radius: 6px;
        }
    
        /* 表格美化 */
        .fixed-table-container {
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 6px rgba(0,0,0,.05);
        }
        .bootstrap-table .table {
            margin-bottom: 0;
        }
        .table thead th {
            background: #2c3e50;
            color: white;
            border-color: transparent !important;
            font-weight: 600;
        }
        .table tbody tr:hover {
            background-color: #f8f9fa !important;
        }
        .table-striped tbody tr:nth-of-type(odd) {
            background-color: rgba(236, 240, 241,.3);
        }
    
        /* 复选框美化 */
        .form-check-input {
            cursor: pointer;
            margin-top: 0.15rem;
        }
        .form-check-label {
            cursor: pointer;
            user-select: none;
        }
    
        @media (max-width: 768px) {
            #toolbar {
                flex-wrap: wrap;
                gap: 1rem;
            }
        }
    </style>
</head>
<body>
    <!-- 工具栏（所有内容强制在一行） -->
    <div id="toolbar">
        <span>启动类型：</span>
        <div class="switch-container">
            <span class="switch-label" id="switch-label-single">单双</span>
            <label class="switch">
                <input type="checkbox" id="start-value">
                <span class="slider"></span>
            </label>
            <span class="switch-label active" id="switch-label-double">大小</span>
        </div>

        <!--span>连续筛选：</span>
        <div id="filter-group">
        </div-->
    </div>
    
    <!-- Toast 容器 -->
    <div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1100">
    <div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
        <strong class="me-auto">系统提醒</strong>
        <small>刚刚</small>
        <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body" id="toast_msg_box">
        </div>
    </div>
    </div>

    <!-- 表格 -->
    <table id="dataTable" class=" "></table>

    <!-- 依赖脚本 -->
    <script src="/static/vendor/jquery/jquery.min.js"></script>
    <script src="/static/vendor/bootstrap/bootstrap.bundle.min.js"></script>
    <script src="/static/vendor/bootstrap-table/bootstrap-table.min.js"></script>


    <script src="/static/common/main.js"></script>
    
    <script>
    $(function() {
        var DT = 'ds';
        var TRANS, TRANS_DS;
        TRANS = TRANS_DS = {
            0: '双',
            1: '单'
        }
        var TRANS_DX = {
            0: '小',
            1: '大'
        }

        var FEAT;

        var URL = '/api/ffk3_conn_feat';

        var LAST_PLAY = null;
        function play(num) {
            if (num == LAST_PLAY) {return }
            const toastLiveExample = document.getElementById('liveToast')
            const toast = new bootstrap.Toast(toastLiveExample)
            $('#toast_msg_box').html('当前期号：' + num + ' 已触发连续！')
            toast.show()

            playAudio();
            LAST_PLAY = num;
        }

        var update_url = (reload) => {
            
            const urlParams = new URLSearchParams(window.location.search);
            FEAT = urlParams.get('feat');
            gte = urlParams.get('gte');
            lte = urlParams.get('lte');

            URL = '/api/ffk3_conn_feat?feat=' + FEAT + '&gte=' + gte + '&lte=' + lte;

            if (reload) {
                $('#dataTable').bootstrapTable('refresh', {
                    url: URL,
                    silent: true,
                });
            }
        }
        update_url(false);
        setInterval(() => {update_url(true)}, 3000);

        // 初始化表格
        $('#dataTable').bootstrapTable({
            responseHandler: function (res, jqXHR) {
                res = res.rows;
                for (var row of res) {

                    row['group'] = `<a href="#" onclick="window.parent.loadPage('pages/predict.html?page=`+(row['page'] - 1)+`&group=`+row['group']+`', false)"> ` + row['group'] + `</a>`

                    row['connHide'] = row['conn'];
                    row['next_num'] = row.num + 1;
                    
                    if (row['type'] == 'ds') {
                        ['predict', 'value', 'next_predict'].map(function (x) {
                            row[x] = TRANS_DS[row[x]];
                        });
                    } else {
                        ['predict', 'value', 'next_predict'].map(function (x) {
                            row[x] = TRANS_DX[row[x]];
                        });
                    }

                    if (row['last']) {
                        col = 'success'
                    } else {
                        col = 'danger'
                    } 

                    if (row['nxt_now'] && row['nxt'] >= 3 && FEAT == 'g7,g4,g4') {
                        play(row['num']);
                    }
                    

                    row['conn'] = Math.abs(row['conn']);
                    
                    row['conn'] =  `<span class="badge fs-6 bg-`+ col + `">` + row['conn'] + `</span>`;
                    if (row['nxt']) {
                        row['nxt'] = Math.abs(row['nxt']);

                        if (row['nxt_now']) {
                            row['nxt'] =  `<span class="badge fs-6 bg-warning">` + row['nxt'] + `</span>`;
                        } else {
                            row['nxt'] =  `<span class="badge fs-6 bg-`+ col + `">` + row['nxt'] + `</span>`;
                        }
                        
                    }

                    if (row['now']) {

                        row['num_desc'] = `<span class="badge bg-warning">` + row['num'] + `</span>`;
                        row['next_num'] = `<span class="badge bg-warning">` + row['next_num'] + `</span>`;
                    } else {
                        row['num_desc'] = row['num'];
                    }



                }
                return {
                    total: res.length,
                    rows: res,
                }
            },
            url: URL,
            toolbar: '#toolbar',
            columns: [{
                field: 'page',
                title: '页面',
            },{
                field: 'group',
                title: '组合'
            },{
                field: 'num',
                title: '期号',
                visible: false,
            },  {
                field: 'num_desc',
                title: '期号',
            }, {
                field: 'predict',
                title: '预测值'
            }, {
                field: 'value',
                title: '实际值'
			},  {
			    field: 'next_num',
			    title: '下期'
			}, {
			    field: 'next_predict',
			    title: '预测'
			},{
                field: 'conn',
                title: '连续',
            },{
                field: 'nxt',
                title: '接下',
            },{
                field: 'connHide',
                title: '连续',
                visible: false,
            }],
            filterControl: true,
            sortName: 'num', 
            sortOrder: 'desc', 
        });

    });
    </script>
</body>
</html>
